import 'package:t3_data_service/biz_data_source/map/address/city_pick/city_pick.dart';

class T3IndexUtils {
  /// 根据[A-Z]排序。
  static void sortListByTag(List<T3IndexModel>? list) {
    if (list == null || list.isEmpty) return;
    list.sort((a, b) {
      if (a.getIndexTag() == "@" || b.getIndexTag() == "#") {
        return -1;
      } else if (a.getIndexTag() == "#" || b.getIndexTag() == "@") {
        return 1;
      } else {
        return a.getIndexTag().compareTo(b.getIndexTag());
      }
    });
  }

  /// 获取索引列表。
  static List<String> getTagIndexList(List<T3IndexModel>? list) {
    List<String> indexData = [];
    if (list != null && list.isNotEmpty) {
      String? tempTag;
      for (int i = 0, length = list.length; i < length; i++) {
        String tag = list[i].getIndexTag();
        if (tempTag != tag) {
          indexData.add(tag);
          tempTag = tag;
        }
      }
    }
    return indexData;
  }

  /// 设置显示悬停Header状态。
  static void setShowStatus(List<T3IndexModel>? list) {
    if (list == null || list.isEmpty) return;
    String? tempTag;
    for (int i = 0, length = list.length; i < length; i++) {
      String tag = list[i].getIndexTag();
      if (tempTag != tag) {
        tempTag = tag;
        list[i].isShowIndex = true;
      } else {
        list[i].isShowIndex = false;
      }
    }
  }
}
